import Vue from 'vue'
import Vuex from 'vuex'
import {
  getAmountLine,
  getMileageLine,
  getUserFlowLine,
  getBusWarnPie,
  getYesterdayData,
  getOperateData,
  getNetworkData,
  getIntevalMileage,
  getAvarageUserFlow
} from '../utils/http'

Vue.use(Vuex)

export function createStore () {
  return new Vuex.Store({
    state: {
      mapScreenVisible: false, // 地图是否全屏
      cityInfo: {
        cityName: '武汉', // 当前城市名称
        cityCode: 420100, // 当前城市编号
        center: [114.298572, 30.584355] // 当前城市中心经纬度
      },
      mobileCityInfo: {
        cityName: '全国', // 当前城市名称
        cityCode: '000000', // 当前城市编号
        center: [114.298572, 30.584355] // 当前城市中心经纬度
      },
      amountWave: {
        xAxis: ["01-23","01-24","02-25","02-26","02-27","02-28","03-01"],
        data0: [1838034.1,2128295.6,2539384.29,2227370.7,2266408.84,2396729.7,4019597.93],
        data1: [5240500.98,4594236.48,5194833.3,4565400.09,4355983.27,4039213.25,3855679.47],
        data2: [4506254.57,3133392.75,3428545.3,3724229.52,4563312.19,4342165.53,4080306.47]
      },
      mileageWave: {
        xAxis: ["01-23","01-24","02-25","02-26","02-27","02-28","03-01"],
        data0: [918493.049,918959.568,966315.673,1009152.698,1030140.533,1135993.033,1174958.613],
        data1: [1448787.183,1408237.195,1356575.731,1357646.816,1383357.626,1387390.903,1371115.379],
        data2: [1393485.859,1395931.026,1368421.126,1395599.946,1403421.993,1398154.714,1382968.463]
      },
      userWave: {
        xAxis: ["01-23","01-24","02-25","02-26","02-27","02-28","03-01"],
        data0: [1291629.0,1465875.0,1505059.0,1534939.0,1559845.0,1646749.0,2881735.0],
        data1: [3544612.0,3107773.0,3140386.0,3049489.0,3086632.0,2895371.0,2768832.0],
        data2: [3200459.0,2432587.0,2549976.0,3374705.0,3209496.0,3166449.0,2959942.0]
      },
      myBusLifeData: {
        fault:29,
        vehicleAlarm:0,
        running:7247,
        normal:8398
      },
      dayTotal: [
        {yesterday:4080306.47,yesterdayPlan:4275800.51},
        {yesterday:1382968.463,yesterdayPlan:1388560.68},
        {yesterday:2959942.0,yesterdayPlan:2900650.0}
      ],
      operateData: [[8398,7247,3671,527],[86.0,44.0],[15852.56,36758,30.08,23.0]],
      networkData: [
        { title: '智能公交APP', payAmount: 0, activeAmount: 30800, downloadAmount: 3256981 },
        { title: '武汉电子公交卡', payAmount: 344829, activeAmount: 240306, downloadAmount: 3823902 }
      ],
      intervalMileage: {
        intervalMileage: 617762.034,
        rate: 44.0
      },
      mobilePayMount: {
        amount: {
          interval: 0,
          yestoday: 0,
          rate: 0
        },
        xAxis: [1, 2, 3, 4, 5, 6],
        data: [0, 0, 0, 0, 0, 0],
      },
      mobilePayCount: {
        amount: {
          interval: 0,
          yestoday: 0,
          rate: 0
        },
        xAxis: [1, 2, 3, 4, 5, 6],
        data: [0, 0, 0, 0, 0, 0],
      },
      mobileCardCount: {
        amount: {
          interval: 0,
          yestoday: 0,
          rate: 0
        },
        xAxis: [1, 2, 3, 4, 5, 6],
        data: [0, 0, 0, 0, 0, 0],
      },
      intervalTotal: [0, 0, 0],
      mapData: [
        [
          {
            name: '武汉',
            value: 1100000
          }
        ],
        [
          {
            name: '上海',
            value: 800000
          }
        ],
        [
          {
            name: '青岛',
            value: 200000
          }
        ],
        [
          {
            name: '张家口',
            value: 90000
          }
        ],
        [
          {
            name: '南京',
            value: 50000
          }
        ]
      ],
      deviceData: [1, 1],
      sexData:[
        {value:1, name:'男'},
        {value:1, name:'女'}
      ],
      areaData: [
        {value:1, name:'本地'},
        {value:1, name:'外地'}
      ],
      ageData: {
        xAxis: ['18-20', '21-30', '31-40', '41-50', '51-60', '60以上'],
        data: [1, 1, 1, 1, 1, 1]
      },
      averagePay: 0,
      averagePayPie: [
        {value:1, name:'1次'},
        {value:1, name:'2次'},
        {value:1, name:'3次'},
        {value:1, name:'4次'},
        {value:1, name:'5次以上'}
      ],
      busAveragePay: 0,
      cityPay: {
        xAxis: ['武汉', '青岛', '嘉兴', '南昌', '天津', '石家庄'],
        dataToday: [0, 0, 0, 0, 0, 0],
        dataYesterDay: [0, 0, 0, 0, 0, 0],
        dataAvg: [0, 0, 0, 0, 0, 0]
      },
      cityMonthPay: {
        xAxis: [1,2,3,4,5,6,7,8,9,10,11,12],
        data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      }
    },
    mutations: {
      MAP_SCREEN_VISIBLE (state, data) {
        state.mapScreenVisible = data
      },
      CITY_INFO (state, { item, data }) {
        state.cityInfo[item] = data
      },
      MOBILE_CITY_INFO (state, { item, data }) {
        state.mobileCityInfo[item] = data
      },
      AMOUNT_LINE (state, data) {
        state.amountWave = data
      },
      MILEAGE_LINE (state, data) {
        state.mileageWave = data
      },
      USER_FLOW_LINE (state, data) {
        state.userWave = data
      },
      BUS_WARN_PIE (state, data) {
        state.myBusLifeData = data
      },
      DAY_TOTAL (state, data) {
        state.dayTotal = data
      },
      OPERATE_DATA (state, data) {
        state.operateData = data
      },
      NETEWORK_DATA (state, data) {
        state.networkData = data
      },
      INTERVAL_MILEAGE (state, data) {
        state.intervalMileage = data
      },
      MOBILE_PAY_MOUNT (state, obj) {
        let {amount, data, xAxis} = {...obj.mobilePayMount}
        state.mobilePayMount.amount = amount
        state.mobilePayMount.data = data
        state.mobilePayMount.xAxis = xAxis
        state.intervalTotal[0] = amount.interval
      },
      MOBILE_PAY_COUNT (state, obj) {
        let {amount, data, xAxis} = {...obj.mobilePayCount}
        state.mobilePayCount.amount = amount
        state.mobilePayCount.data = data
        state.mobilePayCount.xAxis = xAxis
        state.intervalTotal[1] = amount.interval
      },
      MOBILE_CARD_COUNT (state, obj) {
        let {amount, data, xAxis} = {...obj.mobileCardCount}
        state.mobileCardCount.amount = amount
        state.mobileCardCount.data = data
        state.mobileCardCount.xAxis = xAxis
        state.intervalTotal[2] = amount.interval
      },
      INTERVAL_TOTAL (state, data) {
        state.intervalTotal = data.intervalTotal
      },
      MOBILE_MAP (state, data) {
        state.mapData = data.mapData
      },
      DEVICE_DATA (state, data) {
        state.deviceData = data.deviceData
      },
      SEX_DATA (state, data) {
        state.sexData = data.sexData
      },
      AREA_DATA (state, data) {
        state.areaData = data.areaData
      },
      AGE_DATA (state, data) {
        state.ageData = data.ageData
      },
      AVERAGE_PAY (state, data) {
        state.averagePay = data.averagePay
      },
      AVERAGE_PAY_PIE (state, data) {
        state.averagePayPie = data.averagePayPie
      },
      BUS_AVERAGE_PAY (state, data) {
        state.busAveragePay = data.busAveragePay
      },
      CITY_PAY (state, data) {
        state.cityPay = data.cityPay
      },
      CITY_MONTH_PAY (state, data) {
        state.cityMonthPay = data.cityMonthPay
      }
    },
    actions: {
      setMapScreenVisible ({ commit }, data) {
        commit('MAP_SCREEN_VISIBLE', data)
      },
      setCityInfo ({ commit }, payload) {
        commit('CITY_INFO', payload)
      },
      /*async getAmount ({ state, commit }) {
        let data = await getAmountLine(state.cityInfo.cityCode)
        commit('AMOUNT_LINE', data)
      },
      async getMileage ({ state, commit }) {
        let data = await getMileageLine(state.cityInfo.cityCode)
        commit('MILEAGE_LINE', data)
      },
      async getUserFlow ({ state, commit }) {
        let data = await getUserFlowLine(state.cityInfo.cityCode)
        commit('USER_FLOW_LINE', data)
      },
      async getBusWarn ({ state, commit }) {
        let data = await getBusWarnPie(state.cityInfo.cityCode)
        commit('BUS_WARN_PIE', data.BusLife)
      },
      async getDayTotal ({ state, commit }) {
        let data = await getYesterdayData(state.cityInfo.cityCode)
        commit('DAY_TOTAL', data.list)
      },
      async getOperate ({ state, commit }) {
        let data = await getOperateData(state.cityInfo.cityCode)
        commit('OPERATE_DATA', data.list)
      },
      async getIntervalMileage ({ state, commit }) {
        let data = await getIntevalMileage(state.cityInfo.cityCode)
        commit('INTERVAL_MILEAGE', data)
      },*/
      async getNetwork ({ state, commit }) {
        let data = await getNetworkData(state.cityInfo.cityCode)
        commit('NETEWORK_DATA', data)
      }
    }
  })
}
